package com.kungfuhacking.wristbandpro.login.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.kungfuhacking.wristbandpro.R;
import com.kungfuhacking.wristbandpro.base.view.BaseActivity;
import com.kungfuhacking.wristbandpro.custom.TitleBarView;
import com.kungfuhacking.wristbandpro.net.ApiService;


/**
 * 使用条款
 * Created by Aaron on 17/3/29.
 */

public class ClauseActiviry extends BaseActivity {

    private TitleBarView tbv;
    private WebView wv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_webview);
        initView();

    }

    @SuppressLint("SetJavaScriptEnabled")
    private void initView() {

        this.wv = (WebView) findViewById(R.id.wv);
        this.tbv = (TitleBarView) findViewById(R.id.tbv);

        MyWebViewClient client = new MyWebViewClient();

        WebSettings settings = wv.getSettings();

        settings.setDomStorageEnabled(true);
        settings.setJavaScriptEnabled(true);

        wv.setWebViewClient(client);
        wv.loadUrl(ApiService.CLAUSE_IP);
        wv.setWebChromeClient(new WebChromeClient());

        tbv.setOnLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

    @Override
    public void onBackPressed() {

        if (wv.canGoBack())
            wv.goBack();
        else
            super.onBackPressed();

    }
}
